package com.ldy.bigdecimal;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.junit.Test;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @description: BigDecimalTest<br>
 * @copyright: Copyright (c) 2017 ~ 2018<br>
 * @company: 耀方信息技术<br>
 * @author: liudeyong<br>
 * @version: 1.0<br>
 * @createtime: 2018/9/5<br>
 */
public class BigDecimalTest {

    @Test
    public void testBigDecimal() {
        BigDecimal bigDecimal = new BigDecimal("20.4");
        System.out.println(bigDecimal);
        LinkedList<Integer> lists = Lists.newLinkedList();
        lists.add(1);
        lists.add(2);
        lists.add(13);
        Integer[] integers = {1, 2, 13, 15};
        System.out.println(lists.containsAll(Arrays.asList(integers)));
        System.out.println(Integer.MIN_VALUE);
    }

    @Test
    public void testArray() {
        String uniqueKey = "185024-8353-ABDL152412-0-1523";
        // 获得该套餐品的普品uniqueKey
        // 获得该套餐品的普品uniqueKey
        uniqueKey = uniqueKey.substring(0, uniqueKey.lastIndexOf("-") + 1) + 0;
        System.out.println(uniqueKey);

        ArrayList<Integer> integers = Lists.newArrayList(new Integer(1), new Integer(1), new Integer(2));
        HashSet<Integer> integerSet = Sets.newHashSet(integers);
        System.out.println(integerSet);
    }

    @Test
    public void testBeanCopy() {
        List<String> a = Lists.newArrayList("1", "2", "3");
        Iterator<String> iterator = a.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            if (a.size() > 2) {
                if (next.equals("2")) {
                    iterator.remove();
                }
            }
        }

        String s = "[\"1\", \"2\"]";
        List<String> strings = JSONObject.parseObject(s, new TypeReference<List<String>>() {

        });
        System.out.println(strings);
    }

    class A {
        private int field1;
        private String field2;

        public int getField1() {
            return field1;
        }

        public void setField1(int field1) {
            this.field1 = field1;
        }

        public String getField2() {
            return field2;
        }

        public void setField2(String field2) {
            this.field2 = field2;
        }

        public A(int field1, String field2) {
            this.field1 = field1;
            this.field2 = field2;
        }
    }
    class B {
        private int field1;
        private String field2;

        public int getField1() {
            return field1;
        }

        public void setField1(int field1) {
            this.field1 = field1;
        }

        public String getField2() {
            return field2;
        }

        public void setField2(String field2) {
            this.field2 = field2;
        }

        @Override
        public String toString() {
            return "B{" +
                    "field1=" + field1 +
                    ", field2='" + field2 + '\'' +
                    '}';
        }
    }
}
